public class ConnectList {

    public int size;
    public V2 topV2;


    //init method
    public void init(Intersection intersect) {
        if (topV2.intersection == null) {
            topV2.intersection = intersect;
        }
        size++;
    }

    //link and replace
    public void connectRoad(Road road) {
        E2 e2 = new E2();
        e2.road = road;
        e2.nextE2 = topV2.e2;
        topV2.e2 = e2;
    }


    //Calculate the distance between two points
    public double getDistance(Intersection intersect) {
        E2 e2 = topV2.e2;
        while (e2 != null) {
            if (e2.road.intersect1.equals(intersect.IntersectionId) || e2.road.intersect2.equals(intersect.IntersectionId)) {
                return e2.road.distance;
            }
            e2 = e2.nextE2;
        }
        return 0;
    }

    public ConnectList() {
        this.size = 0;
        this.topV2 = new V2();
    }
}
